package com.snopy.concurrency.demo_threadpool;

import com.snopy.concurrency.threadFactory.CustomThreadFactory;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author snopy
 * @version 1.0.0
 * @classname NewCachedThreadPoolTest
 * @description
 * @email 77912204@qq.com
 * @date 2022/02/19 18:51
 */
@Slf4j
public class NewCachedThreadPoolTest {
    static final ExecutorService es = Executors.newCachedThreadPool();
    static final ExecutorService es2 = Executors.newCachedThreadPool(new CustomThreadFactory("cached线程池 "));
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(()->{
                try {
                    TimeUnit.SECONDS.sleep(3);
                    log.info("{}任务结束~",Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            },"线程"+i);

            es.submit(thread);
            es2.submit(thread);
        }
        es.shutdown();
        es2.shutdown();
    }
}
